<?php
session_start();
$title="Check-In ห้องพัก";
include ('header-admin.php');

$userID=$_SESSION["HBD_USER"];
?>

<div id="center-block" class="main-content">
<img src="img/door_checkin.png"/ id="img-block-content">
<div id="content-title-right">
		<h2 class="caption-header">Check-In ห้องพัก</h2>
		<span class="caption">ใช้สำหรับเช็คอินหัองพักหาดบ้านดินรีสอร์ท</span>
	</div>

	<hr><br><br><br><br><br>
			<div id="center-block-right">
			<!--<form action="doCheckIn.php" method="POST" id="checkin-form">-->
			<table>
				<tr>
					<td><label for="reserv_gid">เลขที่จอง</label></td>
					<td><input type="text" id="reserv_gid" name="reserv_gid" value="" size="30" /></td>
				</tr>
				<tr>
					<td><label for="customer_name">ชื่อ</label></td>
					<td><input type="text" id="customer_name" name="customer_name" value="" size="30" /></td>
				</tr>
				<tr>
					<td><label for="customer_surname">นามสกุล</label></td>
					<td><input type="text" id="customer_surname" name="customer_surname" value="" size="30" /></td>
				</tr>
				<tr>
					<td></td>
					<td><input type="button" value="ค้นหารายการจอง" id="find_reserv"/></td>
				</tr>
			</table>
			<br>
			<hr id="delimiter">
			<br>
				
<!--				<p><label for="reserv_id">หมายเลขจอง</label> <input type="text" id="reserv_id" name="reserv_id" value="" size="30" /></p>-->
<!--				<p class="submit"><input type="button" value="ค้นหาหมายเลขจอง" id="find_reserv"/></p><br><br>-->
				<div id="reservdata">
				<form action="doCheckIn.php" method="POST" id="checkin-form">
				<p class="submit" style="display:none;"><input type="submit" value="ยืนยันการเข้าพัก" /></p>
				</form>
				</div>
			</div>
			
			<?php
			$sql="SELECT reservgroup.reserv_gid AS reserv_gid, reservgroup.room_list AS room_list, reservation.reserv_date AS reserv_date, reservation.reserv_begin AS reserv_begin, reservation.reserv_end AS reserv_end, reservation.reserv_etc AS reserv_etc, customer.customer_name AS customer_name, customer.customer_surname AS customer_surname, 
	   		MAX(reservation.reserv_status) AS reserv_current_status, reservgroup.reserv_gdetail AS reserv_gdetail,
	   		reservgroup.reserv_gcost AS reserv_gcost,
	   		reservgroup.reserv_cashpledge AS reserv_cashpledge
			FROM reservgroup
			INNER JOIN customer ON ( reservgroup.customer_id = customer.id )
			INNER JOIN reservation ON ( reservgroup.reserv_gid = reservation.reserv_gid )
   			WHERE reserv_status < '4'
   			GROUP BY reserv_gid
   			ORDER BY reserv_begin ASC, reserv_gid ASC";

	//$result = mysql_query($sql. " LIMIT " . $limit_start. "," . $limit_end);
	$result = mysql_query($sql);
	$count = mysql_num_rows($result);
	$total = mysql_num_rows(mysql_query($sql));
	$status = " ";
	$color = 0;
	$table_notconfirm = "";
	$table_confirmed = "";
	$table_checkined = "";
if($total > 0){
	while ($rs = mysql_fetch_array($result)){
		if($rs['reserv_current_status']<=1){
			$status = 'ยังไม่เรียบร้อย <img src="img/bullet_red.png" style="vertical-align: middle;">';
			if($table_notconfirm_color%2 == 0){
				$table_notconfirm .= '<tr class="odd" ondblclick="viewBooking()">';
			}else{
				$table_notconfirm .= '<tr class="even" ondblclick="viewBooking()">';
			}
			//echo '<tr class="odd">';
			$table_notconfirm .= '<td>' . $rs['reserv_gid'] . '</a>';
			$table_notconfirm .= '</td>';
			$table_notconfirm .= '<td>' . $rs['reserv_begin'] . ' - ' .  $rs['reserv_end'] . '</td>';
			$table_notconfirm .= '<td width="150px">' . $rs['room_list'] . '</td>';
			$table_notconfirm .= '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
			$table_notconfirm .= '<td>' . $status . '</td>';
/* 			$table_notconfirm .= '<td>' . $rs['reserv_gdetail'] . '</td>'; */
			$table_notconfirm .= '<td>' . number_format($rs['reserv_gcost']) . '</td>';
			$table_notconfirm .= '<td>' . number_format($rs['reserv_cashpledge']) . '</td><td>';
			/* if($rs['reserv_current_status']==0) $table_notconfirm .= '<a href="#" onclick="ConfirmChoice_confirm(\'' . $rs['reserv_gid'] . '\'); return false;"><img src="img/icon_confirm.gif" /></a>&nbsp;'; */
			$table_notconfirm .= '<a href="editBooking.php?reserv_id=' . $rs['reserv_gid'] . '&reserv_begin_o='. $rs['reserv_begin'].'&reserv_end_o='. $rs['reserv_end'].'"><img src="img/icon_edit.png" /></a>&nbsp;<a href="#" onclick="ConfirmChoice_del(\'' . $rs['reserv_gid'] . '\'); return false;"><img src="img/icon_delete.png" /></a>';
			$table_notconfirm .= '</td></tr>';
			$table_notconfirm_color++;
		}
		if($rs['reserv_current_status']==2){
			$status = 'ยังใม่เรียบร้อย <img src="img/bullet_yellow.png" style="vertical-align: middle;">';
/* 			$status = 'เรียบร้อยแล้ว <img src="img/bullet_yellow.png" style="vertical-align: middle;">'; */
			/*
if($rs['reserv_current_status']==1){
				$status = 'ยังไม่เรียบร้อย <img src="img/bullet_red.png" style="vertical-align: middle;">';
			}
*/			
			if($table_confirmed_color%2 == 0){
				$table_confirmed .= '<tr class="odd" ondblclick="viewBooking()">';
			}else{
				$table_confirmed .= '<tr class="even" ondblclick="viewBooking()">';
			}
			//echo '<tr class="odd">';
			$table_confirmed .= '<td>' . $rs['reserv_gid'] . '</a>';
			$table_confirmed .= '</td>';
			$table_confirmed .= '<td>' . $rs['reserv_begin'] . ' - ' .  $rs['reserv_end'] . '</td>';
			$table_confirmed .= '<td width="150px">' . $rs['room_list'] . '</td>';
			$table_confirmed .= '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
			$table_confirmed .= '<td>' . $status . '</td>';
/* 			$table_confirmed .= '<td>' . $rs['reserv_gdetail'] . '</td>'; */
			$table_confirmed .= '<td>' . number_format($rs['reserv_gcost']) . '</td>';
			$table_confirmed .= '<td>' . number_format($rs['reserv_cashpledge']) . '</td><td>';
			/* if($rs['reserv_current_status']==0) $table_confirmed .= '<a href="#" onclick="ConfirmChoice_confirm(\'' . $rs['reserv_gid'] . '\'); return false;"><img src="img/icon_confirm.gif" /></a>&nbsp;'; */
			$table_confirmed .= '<a href="editBooking.php?reserv_id=' . $rs['reserv_gid'] . '&reserv_begin_o='. $rs['reserv_begin'].'&reserv_end_o='. $rs['reserv_end'].'"><img src="img/icon_edit.png" /></a>&nbsp;<a href="#" onclick="ConfirmChoice_del(\'' . $rs['reserv_gid'] . '\'); return false;"><img src="img/icon_delete.png" /></a>';
			$table_confirmed .= '</td></tr>';
			$table_confirmed_color++;
		}
		if($rs['reserv_current_status']==3){
			$status = 'เรียบร้อยแล้ว <img src="img/bullet_green.png" style="vertical-align: middle;">';

			if($table_checkined_color%2 == 0){
				$table_checkined .= '<tr class="odd">';
			}else{
				$table_checkined .= '<tr>';
			}
			//echo '<tr class="odd">';
			$table_checkined .= '<td>' . $rs['reserv_gid'] . '</a>';
			$table_checkined .= '</td>';
			$table_checkined .= '<td>' . $rs['reserv_begin'] . ' - ' .  $rs['reserv_end'] . '</td>';
			$table_checkined .= '<td width="150px">' . $rs['room_list'] . '</td>';
			$table_checkined .= '<td>' . $rs['customer_name'].' '.$rs['customer_surname']. '</td>';
			$table_checkined .= '<td>' . $status . '</td>';
/* 			$table_checkined .= '<td>' . $rs['reserv_etc'] . '</td><td>'; */
			$table_checkined .= '<td>' . number_format($rs['reserv_gcost']) . '</td>';
			$table_checkined .= '<td>' . number_format($rs['reserv_cashpledge']) . '</td><td>';
			if($rs['reserv_current_status']==0) $table_checkined .= '<a href="#" onclick="ConfirmChoice_confirm(\'' . $rs['reserv_gid'] . '\'); return false;"><img src="img/icon_confirm.gif" /></a>&nbsp;';
			$table_checkined .= '<a href="editBooking.php?reserv_id=' . $rs['reserv_gid'] . '&reserv_begin_o='. $rs['reserv_begin'].'&reserv_end_o='. $rs['reserv_end'].'"><img src="img/icon_edit.png" /></a>&nbsp;<a href="#" onclick="ConfirmChoice_del(\'' . $rs['reserv_gid'] . '\'); return false;"><img src="img/icon_delete.png" /></a>';
			$table_checkined .= '</td></tr>';
			$table_checkined_color++;
		}
		//if($rs['reserv_current_status']==3)$status = 'เช็คเอาท์แล้ว<img src="img/m_icon_printer.png" style="vertical-align: middle;">';
	}
}
	?>
	<table summary="Table not confirm" id="table">
		<thead>
		<tr>
		<th scope="col" abbr="reserv_id">เลขที่จอง</th>
		<th scope="col" abbr="reserv_begin">วันที่เข้าพัก</th>
		<th scope="col" abbr="room_id">ห้อง</th>
		<th scope="col" abbr="customer_name">ชื่อ-นามสกุล ผู้จอง</th>
		<th scope="col" abbr="customer_name">สถานะ</th>
<!-- 		<th scope="col" abbr="customer_name">รายละเอียด</th> -->
		<th scope="col" abbr="customer_name">จำนวนเงิน</th>
		<th scope="col" abbr="customer_name">มัดจำ</th>
		<th scope="col" abbr="customer_name">จัดการ</th>
		</tr>	
		</thead>
		<tbody>
		<?php echo $table_notconfirm;?>
		</tbody>
	</table>
	
	<table summary="Table confirmed" id="table">
		<thead>
		<tr>
		<th scope="col" abbr="reserv_id">เลขที่จอง</th>
		<th scope="col" abbr="reserv_begin">วันที่เข้าพัก</th>
		<th scope="col" abbr="room_id">ห้อง</th>
		<th scope="col" abbr="customer_name">ชื่อ-นามสกุล ผู้จอง</th>
		<th scope="col" abbr="customer_name">สถานะ</th>
<!-- 		<th scope="col" abbr="customer_name">รายละเอียด</th> -->
		<th scope="col" abbr="customer_name">จำนวนเงิน</th>
		<th scope="col" abbr="customer_name">มัดจำ</th>
		<th scope="col" abbr="customer_name">จัดการ</th>
		</tr>	
		</thead>
		<tbody>
		<?php echo $table_confirmed;?>
		</tbody>
	</table>
	
	<table summary="table checkined" id="table">
		<thead>
		<tr>
		<th scope="col" abbr="reserv_id">เลขที่จอง</th>
		<th scope="col" abbr="reserv_begin">วันที่เข้าพัก</th>
		<th scope="col" abbr="room_id">ห้อง</th>
		<th scope="col" abbr="customer_name">ชื่อ-นามสกุล ผู้จอง</th>
		<th scope="col" abbr="customer_name">สถานะ</th>
<!-- 		<th scope="col" abbr="customer_name">รายละเอียด</th> -->
		<th scope="col" abbr="customer_name">จำนวนเงิน</th>
		<th scope="col" abbr="customer_name">มัดจำ</th>
		<th scope="col" abbr="customer_name">จัดการ</th>
		</tr>	
		</thead>
		<tbody>
		<?php echo $table_checkined;?>
		</tbody>
	</table>
	
	</div>
<?
include ('footer.php');
?>